package com.dgut.hisystem.service.impl;

import com.dgut.hisystem.entity.User;
import com.dgut.hisystem.mapper.DoctorMapper;
import com.dgut.hisystem.mapper.PatientMapper;
import com.dgut.hisystem.mapper.UserMapper;
import com.dgut.hisystem.service.DoctorService;
import com.dgut.hisystem.service.PatientService;
import com.dgut.hisystem.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Resource
    private PatientService patientService;
    @Resource
    private DoctorService doctorService;

    @Override
    public User getUserById(long id) {
        return userMapper.getUserById(id);
    }

    @Override
    public User getUserByPhone(long phone) {
        return userMapper.getUserByPhone(phone);
    }

    @Override
    public void insert(User user) {
        userMapper.insert(user);
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    public void delete(long id) {
        userMapper.delete(id);
    }

    @Override
    public List<User> search() {
        return userMapper.search();
    }

    @Override
    public void deleteByPhone(long phone) {
        userMapper.deleteByPhone(phone);
    }

    @Override
    public void deleteByIdCard(String idCard) {
        User user = userMapper.getUserByIdCard(idCard);

        if (user.getYh_type() == 1) {
            patientService.deleteByYhID(user.getYh_id());
        } else if (user.getYh_type() == 2) {
            doctorService.deleteByYhID(user.getYh_id());
        }

        userMapper.deleteByIdCard(idCard);
    }

    @Override
    public User getUserByIdCard(String idCard) {
        return userMapper.getUserByIdCard(idCard);
    }

    @Override
    public User get(User user) {
        return null;
    }

}
